<?php

namespace app\services\DyService;

class DyLogin
{
    public string $code;

    public function __construct($code)
    {
        $this->code = $code;
    }

    /**
     * 抖音临时登录code换取openid等信息
     * @return array
     */
    public function code2Session()
    {
        $url = "https://developer.toutiao.com/api/apps/v2/jscode2session";
        $header = [
            'content-type' => 'application/json'
        ];
        $body = [
            'appid' => config('pay.dy_app_id'),
            'secret' => config('pay.dy_app_secret'),
            'code' => $this->code
        ];

        [$resCode, $data] = http_post($url, $body, $header);
        return $data;
    }
}